﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Skyworth.CRM.Common;
using Skyworth.CRM.Service.IBLL;

namespace Skyworth.CRM.Web.BasicData
{
    public partial class Productinfo : System.Web.UI.Page
    {
        IProductBLL productBLL = IocContainer.Instance.Resolve<IProductBLL>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if(Request.QueryString["id"]!=null)
                {
                    int productId = 0;
                    int.TryParse(Request.QueryString["id"], out productId);

                    Skyworth.CRM.Service.Entity.Product product = productBLL.GetProductById(productId);

                    this.txtProductName.Text = product.ProductName;
                    this.txtBrandName.Text = product.BrandName;
                    this.txtProductTypeName.Text = product.ProductTypeName;
                    this.txtProductCode.Text = product.ProductCode;
                    this.txtProductModel.Text = product.ProductModel;
                    this.txtProductSize.Text = product.ProductSize;
                    this.txtProductUnit.Text = product.ProductUnit;
                    this.txtUnitVolume.Text = product.UnitVolume;
                    this.txtSource.Text = product.Source;
                    this.txtPackingSize.Text = product.PackingSize;
                    this.txtDescription.Text = product.Desctipion;
                    this.txtIsDetail.Text = product.IsDetail.ToString();

                    string imagesPath ="../ProductImages/Images/";
                    string thumbnailPath = "../ProductImages/Thumbnail/";
                    string noProductImage = thumbnailPath + "No.jpg";
                    this.image1.NavigateUrl = string.IsNullOrEmpty(product.Image1) ? noProductImage :imagesPath+ product.Image1;
                    this.image2.NavigateUrl = string.IsNullOrEmpty(product.Image2) ? noProductImage : imagesPath+product.Image2;
                    this.image3.NavigateUrl = string.IsNullOrEmpty(product.Image3) ? noProductImage : imagesPath + product.Image3;
                    this.image4.NavigateUrl = string.IsNullOrEmpty(product.Image4) ? noProductImage : imagesPath + product.Image4;


                    this.thumbnail1.ImageUrl = string.IsNullOrEmpty(product.Thumbnail1) ? noProductImage : thumbnailPath + product.Thumbnail1;
                    this.thumbnail2.ImageUrl = string.IsNullOrEmpty(product.Thumbnail2) ? noProductImage : thumbnailPath + product.Thumbnail2;
                    this.thumbnail3.ImageUrl = string.IsNullOrEmpty(product.Thumbnail3) ? noProductImage : thumbnailPath + product.Thumbnail3;
                    this.thumbnail4.ImageUrl = string.IsNullOrEmpty(product.Thumbnail4) ? noProductImage : thumbnailPath + product.Thumbnail4;
                    this.thumbnail1.AlternateText =
                    this.thumbnail2.AlternateText =
                    this.thumbnail3.AlternateText = this.thumbnail4.AlternateText = product.ProductName;

                }
            }
        }
    }
}
